<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>正统小六壬占卜程序</title>
    <style>
        body { font-family: '楷体', serif; max-width: 1000px; margin: 30px auto; padding: 20px; background: #f5f3ef }
        .container { border: 3px double #5c4b37; padding: 30px; background: white }
        .input-row { margin: 20px 0; display: flex; align-items: center }
        .input-group { flex: 1; margin-right: 20px }
        select, input { padding: 8px; border: 1px solid #5c4b37; background: #fffaf0 }
        button { background: #8b4513; color: white; padding: 12px 30px; font-size: 16px; letter-spacing: 2px }
        .result { margin-top: 25px; border-top: 2px dashed #5c4b37; padding-top: 20px }
        .gua-title { color: #8b0000; font-size: 24px; margin: 15px 0 }
        .prediction-section { margin: 15px 0; padding: 10px; border-left: 3px solid #8b4513 }
        .lottery { background: #fffde7; padding: 10px; margin: 10px 0 }
    </style>
</head>
<body>
    <div class="container">
        <h1 style="text-align:center;color:#5c4b37">小六壬神课在线占卜</h1>
        
        <!-- 第一行：时间选择 -->
        <div class="input-row">
            <div class="input-group">
                <label>时间选择：</label>
                <select id="yearSelect"></select>年
                <select id="monthSelect"></select>月
                <select id="daySelect"></select>日
                <select id="hourSelect"></select>时
            </div>
        </div>

        <!-- 第二行：数字选择 -->
        <div class="input-row">
            <div class="input-group">
                <label>数字占卜：</label>
                <input type="number" id="numberInput" min="1" max="999" style="width:120px">
                <span>（1-999任意数字）</span>
            </div>
            <button onclick="startDivination()">起课占卜</button>
        </div>

        <div id="result" class="result"></div>
    </div>

<script>
// 初始化时间选择器
function initDateSelectors() {
    // 年份：1900-2100
    const yearSelect = document.getElementById('yearSelect');
    for(let y=1900; y<=2100; y++) yearSelect.add(new Option(y+"年",y));
    
    // 月份：1-12
    const monthSelect = document.getElementById('monthSelect');
    for(let m=1; m<=12; m++) monthSelect.add(new Option(m+"月",m));
    
    // 日期：1-31
    const daySelect = document.getElementById('daySelect');
    for(let d=1; d<=31; d++) daySelect.add(new Option(d+"日",d));
    
    // 时辰：子时-亥时
    const shichen = ["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"];
    const hourSelect = document.getElementById('hourSelect');
    shichen.forEach((v,i) => hourSelect.add(new Option(v+"时",i)));
}
initDateSelectors();

// 正统小六壬算法
function calculateGuaPosition(date) {
    const [year, month, day, hour] = date;
    // 传统月日时三要素计算
    let position = (month % 6) - 1;
    position = (position + day - 1) % 6;
    position = (position + hour) % 6;
    return position >= 0 ? position : 6 + position;
}

// 生成详细卦辞
function generateFullPrediction(guaPos) {
    const guaData = {
        // 六神基础数据
        titles: ["大安青龙", "留连勾陈", "速喜朱雀", "赤口白虎", "小吉玄武", "空亡腾蛇"],
        elements: ["木", "土", "火", "金", "水", "土"],
        
        // 详细预测内容
        事业运程: [
            "宜守成待机，平稳发展，注意文书合约细节",
            "事多反复，需防小人暗算，重要决策宜暂缓",
            "吉星高照，积极进取可得贵人提携",
            "口舌是非多，注意法律纠纷，避免冲动决策",
            "暗藏机遇，北方有利，宜合作求财",
            "诸事不顺，宜修心养性，等待时机"
        ],
        
        婚姻情感: {
            现状: ["稳定和睦", "暧昧不明", "热情发展", "争吵不断", "暗中情缘", "缘分未到"],
            方位: ["东南方文化场所", "西南方餐饮店", "正南方娱乐场所", 
                 "西北方交通枢纽", "北方水边景观", "东北方宗教场所"],
            注意事项: ["注意婆媳关系", "防第三者介入", "避免急于求成",
                 "慎防财务纠纷", "注意健康问题", "不宜仓促决定"]
        },
        
        失物预测: {
            方位: ["东方高处", "西南暗处", "南方火源旁", 
                 "西方金属处", "北方水边", "东北杂物中"],
            找回几率: [85, 40, 70, 55, 65, 30],
            特征: ["有红色物品遮盖", "被移动过位置", "在圆形容器内",
                 "与金属物品相邻", "有液体痕迹", "被多层物品覆盖"]
        },
        
        天气预测: {
            状况: ["晴朗微风", "阴云密布", "骤雨突降", 
                 "大风干燥", "大雾弥漫", "多云转阴"],
            温度: "±" + (guaPos*2) + "℃",
            提示: ["宜晾晒", "带雨具", "防雷电", 
                 "注意防火", "低速驾驶", "添衣保暖"]
        },
        
        财运指导: {
            方位: ["东南", "西南", "正南", 
                 "西北", "正北", "东北"],
            行业: ["木业种植", "地产畜牧", "能源电子",
                 "金融机械", "物流贸易", "宗教文化"],
            贵人特征: ["青衫男子", "中年女性", "红衣人士",
                     "白领人士", "黑衣长者", "僧道人士"]
        }
    };

    // 彩票生成算法
    function generateLottery(redMax, blueMax, redNum, blueNum) {
        const red = Array.from({length:redNum}, () => 
            Math.ceil(Math.random()*redMax)).sort((a,b)=>a-b);
        const blue = Array.from({length:blueNum}, () => 
            Math.ceil(Math.random()*blueMax)).sort((a,b)=>a-b);
        return {red, blue};
    }

    // 构建结果HTML
    return `
        <div class="gua-title">${guaData.titles[guaPos]}卦（${guaData.elements[guaPos]}）</div>
        
        <div class="prediction-section">
            <h3>🔮 事业运程</h3>
            <p>${guaData.事业运程[guaPos]}，贵人方位：${guaData.财运指导.方位[guaPos]}</p>
        </div>

        <div class="prediction-section">
            <h3>💍 婚姻情感</h3>
            <p>当前状态：${guaData.婚姻情感.现状[guaPos]}<br>
            良缘方位：${guaData.婚姻情感.方位[guaPos]}<br>
            注意事项：${guaData.婚姻情感.注意事项[guaPos]}</p>
        </div>

        <div class="prediction-section">
            <h3>🔍 失物寻找</h3>
            <p>遗失方位：${guaData.失物预测.方位[guaPos]}<br>
            环境特征：${guaData.失物预测.特征[guaPos]}<br>
            找回概率：${guaData.失物预测.找回几率[guaPos]}%</p>
        </div>

        <div class="prediction-section">
            <h3>🌤 明日天候</h3>
            <p>天气状况：${guaData.天气预测.状况[guaPos]}<br>
            温度变化：较今日${guaData.天气预测.温度}<br>
            出行提示：${guaData.天气预测.提示[guaPos]}</p>
        </div>

        <div class="lottery">
            <h3>🎫 彩票参考</h3>
            <p>双色球：${generateLottery(33,16,6,1).red.join(' ')} | ${generateLottery(33,16,6,1).blue.join(' ')}<br>
            大乐透：${generateLottery(35,12,5,2).red.join(' ')} | ${generateLottery(35,12,5,2).blue.join(' ')}</p>
        </div>

        <div class="prediction-section">
            <h3>📜 专家建议</h3>
            <p>宜从事${guaData.财运指导.行业[guaPos]}相关事务<br>
            贵人特征：${guaData.财运指导.贵人特征[guaPos]}<br>
            忌讳方位：${guaData.财运指导.方位[(guaPos+4)%6]}</p>
        </div>`;
}

// 起课主函数
function startDivination() {
    let guaPosition;
    
    // 优先使用数字占卜
    const numberInput = document.getElementById('numberInput').value;
    if(numberInput && numberInput >=1 && numberInput <=999) {
        guaPosition = (numberInput % 6 || 6) - 1;
    } 
    // 使用时间占卜
    else {
        const selectedDate = [
            document.getElementById('yearSelect').value,
            document.getElementById('monthSelect').value,
            document.getElementById('daySelect').value,
            document.getElementById('hourSelect').value
        ];
        guaPosition = calculateGuaPosition(selectedDate);
    }
    
    document.getElementById('result').innerHTML = generateFullPrediction(guaPosition);
}
</script>
</body>
</html>